package services

import (
	"errors"
	"hft/Database/admin"
	"hft/global"
)

type Params struct{}

func (*Params) GetParams() (data []*admin.Params, err error) {

	var list []*admin.Params

	global.OC_DB.Find(&list)

	return list, nil
}

func (*Params) CreateParams(data *admin.Params) (err error) {

	res := global.OC_DB.Where("param_name = ?", data.ParamName).FirstOrCreate(&data)

	if res.Error != nil {
		return errors.New("未知错误500")
	}

	if res.RowsAffected == 0 {
		return errors.New("该参数已存在")
	}

	return nil
}

var ParamsService = new(Params)
